package com.rgp.serviceverificationcode.controller;

import com.rgp.internalcommon.dto.ResponseResult;
import com.rgp.internalcommon.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-10 21:16
 */
@RestController
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult<NumberCodeResponse> generateNumberCode(@PathVariable("size") Integer size){

        Integer code = (int)((Math.random() * 9 + 1) * Math.pow(10, size - 1));

//        HashMap<String, Object> map = new HashMap<>();
//        map.put("code",200);
//        map.put("message","success");
//        map.put("data",String.valueOf(code));
//        Gson gson = new Gson();
//        String json = gson.toJson(map);
//        System.out.println(json);
//        return json;

        return ResponseResult.success(new NumberCodeResponse(code));
    }
}
